package com.ctsims.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ctsims.common.core.domain.entity.CtsDor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctsims.common.annotation.Log;
import com.ctsims.common.core.controller.BaseController;
import com.ctsims.common.core.domain.AjaxResult;
import com.ctsims.common.enums.BusinessType;
import com.ctsims.system.service.ICtsDorService;
import com.ctsims.common.utils.poi.ExcelUtil;

/**
 * 宿舍Controller
 *
 * @author hhz
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/system/dor")
public class CtsDorController extends BaseController
{
    @Autowired
    private ICtsDorService ctsDorService;

    /**
     * 查询宿舍列表
     */
    @PreAuthorize("@ss.hasPermi('system:dor:list')")
    @GetMapping("/list")
    public AjaxResult list(CtsDor ctsDor)
    {
        List<CtsDor> list = ctsDorService.selectCtsDorList(ctsDor);
        return success(list);
    }

    /**
     * 导出宿舍列表
     */
    @PreAuthorize("@ss.hasPermi('system:dor:export')")
    @Log(title = "宿舍", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtsDor ctsDor)
    {
        List<CtsDor> list = ctsDorService.selectCtsDorList(ctsDor);
        ExcelUtil<CtsDor> util = new ExcelUtil<CtsDor>(CtsDor.class);
        util.exportExcel(response, list, "宿舍数据");
    }

    /**
     * 获取宿舍详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dor:query')")
    @GetMapping(value = "/{dorId}")
    public AjaxResult getInfo(@PathVariable("dorId") Long dorId)
    {
        return success(ctsDorService.selectCtsDorByDorId(dorId));
    }

    /**
     * 新增宿舍
     */
    @PreAuthorize("@ss.hasPermi('system:dor:add')")
    @Log(title = "宿舍", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtsDor ctsDor)
    {
        return toAjax(ctsDorService.insertCtsDor(ctsDor));
    }

    /**
     * 修改宿舍
     */
    @PreAuthorize("@ss.hasPermi('system:dor:edit')")
    @Log(title = "宿舍", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtsDor ctsDor)
    {
        return toAjax(ctsDorService.updateCtsDor(ctsDor));
    }

    /**
     * 删除宿舍
     */
    @PreAuthorize("@ss.hasPermi('system:dor:remove')")
    @Log(title = "宿舍", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dorIds}")
    public AjaxResult remove(@PathVariable Long[] dorIds)
    {
        return toAjax(ctsDorService.deleteCtsDorByDorIds(dorIds));
    }
}
